package com.bifrost.repository;

import com.bifrost.entity.Permission;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

public interface PermissionRepository extends JpaRepository<Permission, Integer> {

	
	@Query("select p from Permission as p where p.id = ?1")
    Permission findOne(Integer id);
	
	@Query("select p from Permission as p order by p.id")
	List<Permission> findAll();
	
	@Query("select distinct p from Permission as p join fetch p.roles roles where roles.id in (?1)")
	List<Permission> findByGroups(Set<Integer> roles);

	List<Permission> findByType(int type, Sort sort);

	List<Permission> findByParent(Permission parent);


	Permission findByParentAndPermissionName(Permission parent, String name);

    Permission findByIdentifier(String identifier);
}
